/**
 * 是否为对象
 * @param {*} object
 */
export const isObject = (object: any) => {
  return Object.prototype.toString.call(object) === '[object Object]'
}

/**
 * 是否为数组
 * @param {*} array
 */
export const isArray = (array: any) => {
  return Object.prototype.toString.call(array) === '[object Array]'
}

/**
 * 对象深拷贝
 * @param obj 
 * @returns 
 */
export function deepClone(obj: any) {
  let newObj: any = isArray(obj) ? [] : {};
  if (typeof obj !== 'object') {
    return;
  }
  for (let i in obj) {
    newObj[i] = (typeof obj[i] === 'object' && obj[i] != null) ? deepClone(obj[i]) : obj[i];
  }
  return newObj
}

/**
 * 消息提示框
 * @param text 
 * @param icon 
 */
export function totast(text: string, icon?: "none" | "success" | "loading" | "error") {
  uni.showToast({
    title: text || "出错啦~",
    icon: icon || 'none',
  })
}

export default {
  domain: import.meta.env.VITE_BASE_URL,
  totast,
  isArray,
  isObject,
  deepClone,
}